package itheima.com.SocketApi;


import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

// 服务器
public class Socket02TCPServer {

    public static void main(String[] args) throws IOException {

        ServerSocket serverSocket = new ServerSocket(9999);
        System.out.println("服务端发送消息~~~~~~");
        Socket accept = serverSocket.accept();
        System.out.println("服务端accept = "+accept.getClass());
//        System.out.println("socket="+accept.getClass());

        byte[] buf = new byte[1024];
        int renLen = 0;
        InputStream inputStream = accept.getInputStream();
        while ((renLen = inputStream.read(buf))!= -1){
            System.out.println(new String(buf,0,renLen));
        }

        serverSocket.close();
        accept.close();
        inputStream.close();

    }


}
